package com.zhidou;

import com.zhidou.R;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class DxBallActivity extends Activity {

    private DxBallView mDxBallView;
    private static String ICICLE_KEY = "dxball-view";
    private static final String DXBALL_ACT_TAG = "DxBallActivity";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
	mDxBallView = (DxBallView) findViewById(R.id.dxball);
	mDxBallView.setMediaPlay(MediaPlayer.create(getApplicationContext(), R.raw.boing));
	mDxBallView.setTextView((TextView) findViewById(R.id.status));

	if (savedInstanceState == null) {
	    // We were just launched -- set up a new game
	    mDxBallView.setMode(DxBallView.READY);
	} else {
	    // We are being restored
	    Bundle map = savedInstanceState.getBundle(ICICLE_KEY);
	    if (map != null) {
		mDxBallView.restoreState(map);
	    } else {
		mDxBallView.setMode(DxBallView.PAUSE);
	    }
	}
    }

    @Override
    protected void onPause() {
	super.onPause();
	// Pause the game along with the activity
	mDxBallView.setMode(DxBallView.PAUSE);

    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
	// Store the game state
	Log.i(DXBALL_ACT_TAG, "onSaveInstanceState");
	outState.putBundle(ICICLE_KEY, mDxBallView.saveState());
    }

}